<%# locals: (story:, f: nil, linking_comments: [], suggesting: false) -%>
<div>
  <div class="form_errors_header">
    <% if story.errors.any? %>
      <%= errors_for story %>
    <% end %>
    <% if story.is_resubmit? && !suggesting %>
      <div class="flash-notice">
        <p>
          This story has been submitted before. You can resubmit it with a comment to start a fresh discussion.
        </p>

        <%= render partial: "stories/similar", locals: { similar: story.similar_stories } %>
      </div>

      <div>
        <div class="d">
          <strong>What has changed or warrants new discussion?</strong><br>
          (Not just that you think it's still interesting or read it for the first time.)
          <br><br>
        </div>

        <%= label_tag :comment, "Comment:" %>
        <%= text_area_tag "comment", @comment&.comment, :rows => 5 %>
        <br><br>
      </div>
    <% elsif story.similar_stories.any? && !suggesting %>
      <p>Previous discussions for this story:</p>
      <%= render partial: "stories/similar", locals: { similar: story.similar_stories } %>
    <% elsif linking_comments.any? %>
      <div class="flash-notice">
        <p>
        This link has recently appeared in comments:
        </p>
        <ul>
          <% linking_comments.each do |link| %>
            <li>
              Comment <%= link_to link.from_comment.short_id, Routes.comment_target_path(link.from_comment) %>
              <%= time_ago_in_words link.from_comment.last_edited_at %>:
              <%= raw excerpt_fragment_around_link(link.from_comment.markeddown_comment, story.url) %>
            </li>
          <% end %>
        </ul>
        <p>
          Please grow the existing discussion rather than splitting up the discussion.
          Adding a comment will bump it to the top of the <%= link_to "Active stories", active_path %>.
        </p>
      </div>
    <% end %>
  </div>
</div>
